<template>
  <template v-if="props?.name?.includes('el-')">
    <Component :is="getIconName" />
  </template>
  <template v-else>
    <svg aria-hidden="true" class="svg-icon" :width="props.size" :height="props.size" :style="{color: props.color}">
      <use :xlink:href="symbolId" rel="external nofollow" />
    </svg>
  </template>
</template>

<script setup>
import { computed } from 'vue';
const props = defineProps({
  prefix: {
    type: String,
    default: 'icon'
  },
  name: {
    type: String,
    default: '',
    required: true
  },
  color: {
    type: String,
    default: ''
  },
  size: {
    type: String,
    default: '1em'
  }
});

const symbolId = computed(() => `#${props.prefix}-${props.name}`);
const getIconName = computed(() => {
  let name = props?.name;
  if (name) {
    name = name.substring(3)?.toLowerCase();
    if (name==='menu') return 'IconMenu';
    name = name.replace(/\b\w+\b/g, (word) => {
      return word.substring(0, 1).toUpperCase() + word.substring(1);
    });
  }
  return name;
});
</script>

<style lang="scss" scoped>

  .svg-icon {
    color: inherit;
    fill: currentcolor;
  }
</style>
